package noobteam.deartrainer.service;

import noobteam.deartrainer.mapper.TrainerInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 高乾威
 */
@Service
public class TrainerInfoService {

    @Resource
    private TrainerInfoMapper trainerInfoMapper;

    /**
     * 监控注册功能：向用户信息表（usersinfo）插入用户名和密码
     */
    public boolean doSaveTrainer(Map<String,String> map){
        boolean flag=false;
        //选择要添加监控的代码
        //ctrl+alt+t 打开 surround with窗口 选择 try catch
        try {
            boolean r = trainerInfoMapper.insertTrainer(map);
            if(r){
                flag=true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            //记录日志，写到文件中进行保存
        }
        return flag;
    }

    public List<Map<String,Object>> getTrainerPhone(){
        List<Map<String,Object>> list = null;
        try {
            list = trainerInfoMapper.selectTrainerPhone();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public Map<String,Object> getTrainerInfoByPhone(String str){
        Map<String, Object> map = null;
        try {
            map = trainerInfoMapper.selectTrainMsgByPhone(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    public boolean updateTrainerMsg(Map<String, String> map) {
        boolean isSucceed = false;
        try {
            isSucceed = trainerInfoMapper.updateTrainerMsg(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    public boolean updateTrainerPassword(Map<String, String> map) {
        boolean isSucceed = false;
        try {
            isSucceed = trainerInfoMapper.updatePassword(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    public List<Map<String, Object>> getTrainersList() {
        List<Map<String, Object>> list = null;
        try {
            list = trainerInfoMapper.getTrainersList();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getTrainersListOrderByOnJobTime() {
        List<Map<String, Object>> list = null;
        try {
            list = trainerInfoMapper.getTrainersListOrderByOnJobTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getTrainersListOrderByAge() {
        List<Map<String, Object>> list = null;
        try {
            list = trainerInfoMapper.getTrainersListOrderByAge();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getTrainersListOrderByExperience() {
        List<Map<String, Object>> list = null;
        try {
            list = trainerInfoMapper.getTrainersListOrderByExperience();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getTrainersListBySex(String trainerSex) {
        List<Map<String, Object>> list = null;
        try {
            list = trainerInfoMapper.getTrainersListBySex(trainerSex);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public boolean updateTrainerImage(Map<String, String> trainer) {
        boolean isSucceed = false;
        try {
            isSucceed = trainerInfoMapper.updateTrainerImage(trainer);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    public boolean deleteTrainer(String phone) {
        boolean isSucceed = false;
        try {
            isSucceed = trainerInfoMapper.deleteTrainer(phone);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }
}
